﻿/*
COPYRIGHT (C) 2009 EPISERVER AB

THIS FILE IS PART OF REMOTE PAGE PROVIDER FOR EPISERVER CMS.
REMOTE PAGE PROVIDER FOR EPISERVER CMS IS FREE SOFTWARE: YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE VERSION v2.1 AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.

REMOTE PAGE PROVIDER FOR EPISERVER CMS IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE ALONG WITH REMOTE PAGE PROVIDER FOR EPISERVER CMS]. IF NOT, SEE <HTTP://WWW.GNU.ORG/LICENSES/>.
*/
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using EPiServer;
using EPiServer.DataAbstraction;
using EPiServer.Security;
using System.ServiceModel.Security;
using System.Net;
using EPiServer.Core;

namespace EPiServer.Labs.RemoteProvider
{
    /// <summary>
    /// The Credentilas which sends between client and server in intializing
    /// </summary>
    [DataContract]
    public class ProviderCredentials
    {
        public ProviderCredentials()
        {
        }

        public ProviderCredentials(string userName)
        {
            UserName = userName;
            Password = string.Empty;
            Domain = string.Empty;
        }

        public ProviderCredentials(string userName, string password)
        {
            UserName = userName;
            Password = password;
            Domain = string.Empty;
        }

        public ProviderCredentials(string userName, string password, string domain)
        {
            UserName = userName;
            Password = password;
            Domain = domain;
        }

        [DataMember]
        public string UserName
        {
            get;
            set;
        }

        [DataMember]
        public  string Password
        {
            get;
            set;
        }

        [DataMember]
        public string Domain
        {
            get;
            set;
        }

    }

    /// <summary>
    /// The Intialize data which sends in the beging of handskaking client and server
    /// </summary>
    [DataContract]
    public class InitializeData
    {
        public InitializeData() { }
        public InitializeData(InitializeData initializeData) 
        {
            CapabilitySupported = initializeData.CapabilitySupported;
            Credential = initializeData.Credential;
            RemoteSiteSecret = SiteSecurity.SiteSecret;
            RemoteSiteId = Configuration.Settings.Instance.Parent.SiteId;
        }

        [DataMember]
        public PageProviderCapabilities CapabilitySupported
        {
            get;
            set;
        }


        [DataMember]
        public ProviderCredentials Credential
        {
            get;
            set;
        }

        [DataMember]
        public byte[] RemoteSiteSecret
        {
            get;
            set;
        }

        [DataMember]
        public string RemoteSiteId
        {
            get;
            set;
        }

        [DataMember]
        public Int32 WasteBasketID
        {
            get;
            set;
        }

        [DataMember]
        public RemoteVirtualPathProvidersInfo RemoteVirtualPathProvidersInfo
        {
            get;
            set;
        }

    }

    /// <summary>
    /// The class RemotePageRaw is a Data Contract which is used in Remote Page Provider concept.
    /// It is a light weight version of PageData.
    /// </summary>
    [DataContract]
    [KnownType(typeof(PageAccessControlList))]
    public class RemotePageRaw
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="RemotePageRaw"/> class.
        /// </summary>
        public RemotePageRaw() 
        {
            Data = new Dictionary<string, string>();
            Type = new Dictionary<string, string>();
            Languages = new List<string>();
            ACL = new AccessControlList();
        }


        /// <summary>
        /// Gets or sets the data (which is Property Name and Property value of PageData.
        /// Key is Property Name
        /// Value is Property Value
        /// </summary>
        /// <value>The data.</value>
        [DataMember]
        public Dictionary<string, string> Data
        {
            get;
            set;
        }


        /// <summary>
        /// Gets or sets the type which is the Property Name and Property Type PageData
        /// Key is Property Name
        /// Value is Property Type
        /// </summary>
        /// <value>The type.</value>
        [DataMember]
        public Dictionary<string, string> Type
        {
            get;
            set;
        }


        /// <summary>
        /// Gets or sets the ACL which is Access Control List.
        /// </summary>
        /// <value>The ACL.</value>
        [DataMember]
        public AccessControlList ACL
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the languages which is supported languages
        /// </summary>
        /// <value>The languages.</value>
        [DataMember]
        public List<string> Languages
        {
            get;
            set;
        }
    }

    /// <summary>
    /// RemoteProviderFault class pack server exception's message and send it to teh client
    /// </summary>
    [DataContract]
    public class RemoteProviderFault 
    {
        public RemoteProviderFault()
        {
            ErrorMessage = string.Empty;
        }
        public RemoteProviderFault(string errorMessage)
        {
            ErrorMessage = errorMessage;
        }


        [DataMember]
        public string ErrorMessage
        { get; set; }

    }
}
